#include "hardware_buffer.h"
#include <stdexcept>

using namespace krryn::view;

hardware_buffer::hardware_buffer(size_t a_SizeInBytes) 
	: m_Locked(none), m_SizeInBytes(a_SizeInBytes) {}

void* hardware_buffer::lock(lock_type a_Type){
	if(m_Locked == none){
		if(a_Type == none){
			unlock();
			return 0;
		}else{
			m_Locked = a_Type;
			return lock_impl();
		}
	}else{
		throw std::runtime_error("Can't lock buffer, buffer already locked");
	}
}

void hardware_buffer::unlock(){
	if(m_Locked != none){
		m_Locked = none;
		unlock_impl();
	}else{
		throw std::runtime_error("Can't unlock buffer, buffer wasn't locked");
	}
}

hardware_buffer::lock_type hardware_buffer::locked(){
	return m_Locked;
}

size_t hardware_buffer::get_size_in_bytes() const { return m_SizeInBytes; }